﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMO.Models;

namespace SMO.Models.SimplObject
{
    public class StockTransactionRepository
    {
        private SMO_LinQDataContext datacontent = new SMO_LinQDataContext();
        public IQueryable<StockTransaction> GetAll()
        {
            return datacontent.StockTransactions;
        }

        public StockTransaction GetByStockTransactionID(string id)
        {
            return datacontent.StockTransactions.SingleOrDefault(s => s.StockTransactionId.ToString().Trim() == id.Trim());
        }

        public IQueryable<StockTransaction> GetByStockID(string id)
        {
            return datacontent.StockTransactions.Where(s => s.StockId.ToString().Trim() == id.Trim());
        }

        public IQueryable<StockTransaction> GetByPorfolioID(string id)
        {
            return datacontent.StockTransactions.Where(s => s.PorfolioId.ToString().Trim() == id.Trim());
        }

        public IQueryable<StockTransaction> GetByPorfolioIDandStockID(string p_id,string s_id)
        {
            return datacontent.StockTransactions.Where(s => s.PorfolioId.ToString().Trim() == p_id.Trim() && s.StockId.ToString().Trim() == s_id.Trim());
        }

        public StockTransaction GetFirst()
        {
            return datacontent.StockTransactions.FirstOrDefault();
        }

        public void Add(StockTransaction stocktransaction)
        {
            datacontent.StockTransactions.InsertOnSubmit(stocktransaction);
        }

        public void Delete(StockTransaction stocktransaction)
        {
            datacontent.StockTransactions.DeleteOnSubmit(stocktransaction);
        }

        public void Save()
        {
            datacontent.SubmitChanges();
        } 
    }
}
